/**
 * 
 */
package br.com.rodolfo.timesheet.dao;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import br.com.rodolfo.timesheet.entity.Login;

/**
 * @author rodolfo
 *
 */

@Repository("loginDao")
public class LoginDAO {
	
	@PersistenceContext
	protected EntityManager entityManager;
	
	
	@Transactional(readOnly=true)
	public Login findByLoginSenha(Login bean)
		throws Exception{
		StringBuilder str = new StringBuilder("from Login l where ");
		str.append("l.login = :username and ");
		str.append("l.pwd = :password");
		
		Query q = entityManager.createQuery(str.toString());
		q.setParameter("username", bean.getLogin());
		q.setParameter("password", bean.getPwd());
		Login l = (Login) q.getSingleResult();
		return l;
	}
	
	
	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}

}
